//
//  ETH+Keystore.swift
//  XHWalletUtils
//
//  Created by xinph on 2020/5/16.
//  Copyright © 2020 xinph. All rights reserved.
//

import Foundation

extension Wallet {
    
    /// 验证keystore合法性
    /// - Parameter password: keystore文件密码
    func vertifyKeystore(_ password: String) -> Bool {
        guard let ks = self.keystore else { return false }
        guard let keystore = BIP32Keystore(ks) else { return false }
        guard let add = self.accounts.first?.address else { return false }
        guard let address = EthereumAddress(add) else { return false }
        do {
            _ = try keystore.UNSAFE_getPrivateKeyData(password: password, account: address)
            return true
        } catch {
            return false
        }
    }
}
